//
// Created by francklinson on 2021/10/23 AT 12:36.
//
#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <algorithm>
#include <functional>
#include <climits>
#include <string>
#include "../myTool.h"

//using namespace std;
class Base {
public:
    Base() {
        std::cout << "Base Constructed" << std::endl;
    }

    virtual ~Base() {
        std::cout << "Base Destructed" << std::endl;
    }
    // 虚函数的作用：告诉编译器 子类中该方法会覆写  到vtable中去找
};

class Derived : public Base {
private:
    int *array;
public:
    Derived() {
        array = new int[5];
        std::cout << "Derived Constructed" << std::endl;
    }

    ~Derived() {
        delete array;
        std::cout << "Derived Destructed" << std::endl;
    }
};

int main() {
    Base *base = new Base();
    delete base;
    std::cout << "---------------------" << std::endl;
    int a = 20;
    Derived *derived = new Derived();
    delete derived;
    std::cout << "---------------------" << std::endl;
    Base *poly = new Derived();
    delete poly; // 不会调用子类的析构
    return 0;
}

